package com.jzz.eletuanbackend.mapper;

import com.jzz.eletuanbackend.entity.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface UserMapper {

    @Select("SELECT id FROM v_user WHERE `type`=#{type} AND `phone`=#{phone} AND `password`=#{password} LIMIT 1")
    Integer signIn(@Param("type") String type, @Param("phone") String phone, @Param("password") String password);

    @Insert("INSERT INTO customer (phone, displayName, password, receiveInfo) VALUES (#{phone}, #{displayName}, #{password}, #{receiveInfo})")
    Integer signUpAsCustomer(
            @Param("phone") String phone,
            @Param("displayName") String displayName,
            @Param("password") String password,
            @Param("receiveInfo") String receiveInfo
    );

    @Insert("INSERT INTO deliverer (phone, name, healthId, password) VALUES (#{phone}, #{name}, #{healthId}, #{password})")
    Integer signUpAsDeliverer(
            @Param("phone") String phone,
            @Param("name") String name,
            @Param("healthId") String healthId,
            @Param("password") String password
    );

    @Insert("INSERT INTO business (phone, password) VALUES (#{phone}, #{password})")
    Integer signUpAsBusiness(@Param("phone") String phone,
                             @Param("password") String password);

    @Select("SELECT * FROM v_user WHERE `type` = #{type} AND `id` = #{id} LIMIT 1")
    User get(@Param("type") String type, @Param("id") Long id);
}
